package com.tudouji.project.purchasebill.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.flow.service.pojo.BasePojo;
import com.flow.service.pojo.flow.FlowTempNode;
import com.flow.service.pojo.result.FlowResult;
import com.tudouji.framework.aspectj.lang.annotation.Excel;
import com.tudouji.project.bill.domain.Whinformitem;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 采购单对象 purchasebill
 *
 * @author tudouji
 * @date 2022-04-11
 */
@Slf4j
@Data
public class Purchasebill extends BasePojo
{
    private static final long serialVersionUID = 1L;

    /** $column.columnComment */
    private Long id;

    private String guid;

    /** $column.columnComment */
    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
    private String code;

    /** 采购日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "采购日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date purchdate;

    /** 采购主体id */
    @Excel(name = "采购主体id")
    private String orgid;

    private Long orgId;

    /** 采购主体 */
    @Excel(name = "采购主体")
    private String orgname;

    /** 采购部门id */
    @Excel(name = "采购部门id")
    private String departid;

    /** 采购部门 */
    @Excel(name = "采购部门")
    private String department;

    /** 采购总重量 */
    @Excel(name = "采购总重量")
    private BigDecimal totalweight;

    private BigDecimal unpaidWeight;
    private BigDecimal unpaidSettlement;
    private BigDecimal unpaidCount;

    /** 采购总数量 */
    @Excel(name = "采购总数量")
    private BigDecimal totalnum;

    /** 总金额 */
    @Excel(name = "总金额")
    private BigDecimal totalamount;

    /** 供应商id */
    @Excel(name = "供应商id")
    private String supplierid;

    /** 供应商 */
    @Excel(name = "供应商")
    private String supplier;

    /** 币种:1-人民币2-美金 */
    @Excel(name = "币种:1-人民币2-美金")
    private Integer currency;

    /** 汇率 */
    /** 2023-06-28修改为多次入库的判断标识 */
    @Excel(name = "汇率")
    private BigDecimal exchangerate;

    /** 是否含税:1-是 2-否 */
    @Excel(name = "是否含税:1-是 2-否")
    private Integer isintax;

    /** 是否价外税:1-是 2-否 */
    @Excel(name = "是否价外税:1-是 2-否")
    private Integer ispriceintax;

    /** 创建人 */
    @Excel(name = "创建人")
    private String operatorid;

    private String keywords;

    /** 创建人 */
    @Excel(name = "创建人")
    private String operator;

    /** $column.columnComment */
    @Excel(name = "创建人")
    private String flowtempguid;

    /** 状态 */
    @Excel(name = "状态")
    private Integer status;
    /** 业务类型 */
    private Integer type;
    private Integer paystatus;
    private String payStatusName;

    /** 库房id */
    @Excel(name = "库房id")
    private String srguid;

    private Long strmId;

    /** 库房名称 */
    @Excel(name = "库房名称")
    private String srname;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createtime;

    // 检索条件
    private String[] roomids;
    private Integer[] stats;// 状态组
    private List<Purchasebillitem> items;// 采购明细
    private List<FlowTempNode> nodes;

    private String[] depids;
    private String statusname;
    private String createbyname;
    private String keyword;
    private String reciever_id;
    private String remark;
    private String search;

    private List<Whinformitem> whinitems;

    private String[] guids;


    private String supplierId;
    private String supplierName;
    private String orgName;
    private String time;
    private String typeName;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date startdate;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date enddate;
    @Excel(name = "产品")
    private String productname;
    @Excel(name = "规格")
    private String spname;
    @Excel(name = "单价")
    private BigDecimal price;
    @Excel(name = "数量")
    private BigDecimal count;
    @Excel(name = "金额")
    private BigDecimal amount;


    @Override
    public boolean backToStartNode(FlowResult result){
        if (getPaystatus().intValue()>2){
            result.setMsg("已发起付款申请，不能退回到发起");
            return false;
        }
        return  true;
    }
    @Override
    public void prepareForProcess(){
        log.info("set values for flow process in Puc vo:");
        setBusTable("purchasebill");
        setPlatformId(getStrmId());
        setToPlatformId(getStrmId());
    }
}
